﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class LocalStringResourceService : ILocalStringResourceService
    {
        private ILocalStringResourceRepository _localeStringResourceRepository;

        #region ILocaleStringResourceService Members

        /// <summary>
        /// create new LocaleStringResource
        /// </summary>
        /// <param name="theNewLocaleStringResource">the new LocaleStringResource instance</param>
        /// <returns>the new LocaleStringResource's ID</returns>
        public int CreateNewLocaleStringResource(Data.Entity.LocalStringResource theNewLocaleStringResource)
        {
            if (theNewLocaleStringResource == null)
            {
                return 0;
            }

            if (_localeStringResourceRepository == null)
            {
                _localeStringResourceRepository = new LocalStringResourceRepository();
            }

            return _localeStringResourceRepository.CreateNewLocaleStringResource(theNewLocaleStringResource);
        }

        public IList<Data.Entity.LocalStringResource> GetLocaleStringResourceByLanguage(int languageID)
        {
            if (languageID <= 0)
            {
                return null;
            }

            if (_localeStringResourceRepository == null)
            {
                _localeStringResourceRepository = new LocalStringResourceRepository();
            }

            return _localeStringResourceRepository.GetLocaleStringResourceByLanguage(languageID);
        }

        public int UpdateLocaleStringResource(Data.Entity.LocalStringResource theLocaleStringResource)
        {
            if (theLocaleStringResource == null || theLocaleStringResource.LocaleStringResourceID <= 0)
            {
                return 0;
            }

			if(_localeStringResourceRepository == null)
			{
				_localeStringResourceRepository = new LocalStringResourceRepository();
			}

			return _localeStringResourceRepository.UpdateLocaleStringResource(theLocaleStringResource);
        }

		public IList<Data.Entity.LocalStringResource> GetAllLocaleStringResource()
		{
			if(_localeStringResourceRepository == null)
			{
				_localeStringResourceRepository = new LocalStringResourceRepository();
			}

			return _localeStringResourceRepository.GetAllLocaleStringResource();
		}

		public int DeleteLocaleStringResource(int id)
		{
			if(id <= 0)
			{
				return 0;
			}

			if(_localeStringResourceRepository == null)
			{
				_localeStringResourceRepository = new LocalStringResourceRepository();
			}

			return _localeStringResourceRepository.DeleteLocaleStringResource(id);
		}

		public Data.Entity.LocalStringResource GetTheLocalStringResource(int id)
		{
			if(id <= 0)
			{
				return null;
			}

			if(_localeStringResourceRepository == null)
			{
				_localeStringResourceRepository = new LocalStringResourceRepository();
			}

			return _localeStringResourceRepository.GetTheLocalStringResource(id);
		}

		#endregion
	}
}
